﻿using System.AddIn.Pipeline;
using Bookvar.AddIn;
using Bookvar.AddIns.Contracts;
using Bookvar.ObjectModel;
using System;

namespace Bookvar.AddIn.HostAdapters
{
    [HostAdapter]
    public class BookvarContractToViewHostAdapter : BookvarHostView, IDisposable
    {
        private readonly IBookvarContract contract;
        private ContractHandle handle;

        public BookvarContractToViewHostAdapter( IBookvarContract contract )
        {
            this.contract = contract;
            handle = new ContractHandle( contract );
        }

        public override void Execute( Topic topic )
        {
            contract.Execute( topic.Clone() );
        }

        public override AddinInfo GetInfo()
        {
            return contract.Info;
        }

		#region IDisposable Members

		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(this);
		}
		
		protected virtual void Dispose(bool keep)
		{
			if(keep)
			{
				handle.Dispose();
			}
		}

		#endregion
	}
}